<?php
class ImageUtils {
	
	public static function data2img($imgsrc) {
		
		$handle = fopen($imgsrc, "rb");
		$contents = '';
		while (!feof($handle)) {
			$contents .= fread($handle, 1024);
		}
		fclose($handle);
		
		return  $contents;
	}

	

	public function savepic($jpg) {
		
		
		//每日一个目录
		$today=date("Ymd");
		$dir="images/{$today}";
		createDir($dir);
		//file name
		//$arg = array("6", "fileserno.txt", ",","","");
		//$obj = spClass("FileSerNo", $arg);
		$current_date = date("Ymd");
		$fileno=FileUtils::getOrUpdateNumber($today, 1);	
		$filename = $dir . $fileno . ".jpg";
		file_put_contents($filename, $jpg);

	}

	private function createDir($path) {
		if (!file_exists($path)) {
			createDir(dirname($path));
			mkdir($path, 0777);
		}
	}

}
?>